﻿using GrainManage.Entities;
using GrainManage.Server.Cache;
using System;
using System.Collections.Generic;

namespace GrainManage.Server.Business
{
    public class BaseBusiness
    {
        private static List<int> IgnoredStatus = new List<int> { StatusCode.Success, StatusCode.NoData };
        protected static void SetResponse(int statusCode, object input, BaseOutputModel output)
        {
            output.Status = new StatusInfo { StatusCode = statusCode, Message = CachedStatusMessage.GetMessage(statusCode) };
            if (!IgnoredStatus.Contains(statusCode))
            {
                LogUtil.Write(2, LogLevel.Warn, input, output, null);
            }
        }

        protected static void SetResponse(int statusCode, object input, BaseOutputModel output, Exception e)
        {
            output.Status = new StatusInfo { StatusCode = statusCode, Message = e.Message };
            if (!IgnoredStatus.Contains(statusCode))
            {
                LogUtil.Write(2, LogLevel.Error, input, output, e);
            }
        }
    }
}
